package com.createdevelopment.gaoyou;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.createdevelopment.gaoyou.util.Weather;

public class MainActivity extends Activity {
	
	private ImageView vision;
	private ImageView invest;
	private ImageView learnmore;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		 TextView weatherInfo;
		 prepareNetConnection();
		 Weather weather=new Weather().getCurrentWeather();		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
//		weatherInfo=(TextView)findViewById(R.id.weather);
//		weatherInfo.setText(weather.getTemMin()+"~"+weather.getTemMax()+" "+weather.getWeather());
		findElements();
		vision.setOnClickListener(onClickListener);
		invest.setOnClickListener(onClickListener);
		learnmore.setOnClickListener(onClickListener);
	
		
	}
    
	
	OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent = new Intent();
			if(v	==	vision){
				intent =new Intent(MainActivity.this,AboutActivity.class);
				
			}else if (v == invest) {
				intent =new Intent(MainActivity.this,InvestmentActivity.class);
				
			}else if (v == learnmore) {
				intent =new Intent(MainActivity.this,VisionActivity.class);
			}
			startActivity(intent);
		}
	};
	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	private void findElements(){
		vision=(ImageView)this.findViewById(R.id.visionMenuItem);
		invest=(ImageView)this.findViewById(R.id.investmentMenuItem);
		learnmore=(ImageView)this.findViewById(R.id.learnMoreMenuItem);
	}
	
	/*
	 * We need to do prepare net connect,if not. We will not allowed to 
	 * use httpclient.
	 */
	@SuppressLint("NewApi")
	private void prepareNetConnection(){
		 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
		 .detectDiskReads()
		 .detectDiskWrites()
		 .detectNetwork() // ��������滻ΪdetectAll() �Ͱ����˴��̶�д������I/O
		 .penaltyLog() //��ӡlogcat����ȻҲ���Զ�λ��dropbox��ͨ���ļ�������Ӧ��log
		 .build());
		 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
		 .detectLeakedSqlLiteObjects() //̽��SQLite��ݿ����
		 .penaltyLog() //��ӡlogcat
		 .penaltyDeath()
		 .build()); 
	}

}
